package com.eqdd.yiqidian.ui.discover.workdiary;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.eqdd.yiqidian.ListItem139Custom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.recycleadapter.ItemClickSupport;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.WorkDiaryBean;
import com.eqdd.yiqidian.bean.rebuild.RenwuInfoResultBean;
import com.eqdd.yiqidian.box.ItemDecoration.SectionDividerItemDecoration;
import com.eqdd.yiqidian.box.span.NoLineClickSpan;
import com.eqdd.yiqidian.helper.mvchelper.ModelRx2DataSource;
import com.eqdd.yiqidian.helper.mvchelper.Rx2DataSource;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.http.JsonConverter;
import com.eqdd.yiqidian.ui.InputDialogActivity;
import com.eqdd.yiqidian.ui.mine.UserCardActivity;
import com.eqdd.yiqidian.utils.CopyUtil;
import com.eqdd.yiqidian.utils.DensityUtil;
import com.eqdd.yiqidian.utils.HttpUtil;
import com.eqdd.yiqidian.utils.ImageUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.shizhefei.mvc.MVCCoolHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.rong.imkit.utils.RongDateUtils;

public class WorkDiaryCommentActivity extends BaseActivity {
    private ListItem139Custom dataBinding;
    private SlimAdapterEx<WorkDiaryBean.CommentBean> mSlimAdapterEx;
    private SimpleDateFormat sf;
    private int pageNum;
    private String talkTo;
    private SlimAdapterEx<WorkDiaryBean.CommentBean> slimTalkAdapter;
    private boolean isCommentUp;
    private int dealPos;
    private boolean isMyComment;
    private int commentId;
    private String talkContent;
    private int type;
    private MaterialDialog moreDialog;
    private int diaryId;
    private int parentId = 0;
    private String parentUserGuid;
    private int firstCommentId;
    private MVCCoolHelper<List<WorkDiaryBean.CommentBean>> mvcHelper;
    private int id;
    private String mType; //1-任务，０－日志
    private LayoutInflater inflater;

    @Override
    public void initBinding() {
        mType = getIntent().getStringExtra(Config.TYPE);
        dataBinding = DataBindingUtil.setContentView(this, R.layout.list_item_139);
        inflater = LayoutInflater.from(this);
        String title = "详情";
        if ("0".equals(mType)) {
            title = "日志详情";
        } else if ("1".equals(mType)) {
            title = "任务详情";
        }
        initTopTitleBar(View.VISIBLE, title);
    }

    @SuppressWarnings("unchecked")
    @Override
    public void initData() {
        id = getIntent().getIntExtra(Config.ID, 0);
        sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.CHINA);

        setRecyclerViewMoveFast(new LinearLayoutManager(this), dataBinding.recyclerView);
        mSlimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_36, new SlimInjector<WorkDiaryBean.CommentBean>() {
            @Override
            public void onInject(WorkDiaryBean.CommentBean data, IViewInjector injector) {
                try {
                    List<WorkDiaryBean.CommentBean> commentResultBeen;
                    if (data.getChildList() != null) {
                        commentResultBeen = data.getChildList();
                    } else {
                        commentResultBeen = new ArrayList<>();
                    }
                    RecyclerView recyclerView = (RecyclerView) injector.findViewById(R.id.recyclerViewCommentComment);

                    recyclerView.setLayoutManager(new LinearLayoutManager(WorkDiaryCommentActivity.this));
                    SlimAdapterEx<WorkDiaryBean.CommentBean> slimAdapterExCommentChild = SlimAdapterEx.create().register(R.layout.list_item_37, new SlimInjector<WorkDiaryBean.CommentBean>() {
                        @Override
                        public void onInject(WorkDiaryBean.CommentBean data, IViewInjector injector) {
                            injector.with(R.id.tv_comment_comment, view -> {
                                TextView textView = (TextView) view;
                                SpannableString spStr = new SpannableString(data.getCreateStaffName() + ":" + " @" + data.getParentStaffName() + " " + data.getContent());
                                NoLineClickSpan firstSpan = new NoLineClickSpan("#3423ff", v -> {

                                    Bundle bundle = new Bundle();
                                    bundle.putString(Config.GUID, data.getCreater());
                                    startActivity(UserCardActivity.class, bundle);
                                });
                                NoLineClickSpan secondSpan = new NoLineClickSpan("#3423ff", v -> {
                                    Bundle bundle = new Bundle();
                                    bundle.putString(Config.GUID, data.getParentUserGuid());
                                    startActivity(UserCardActivity.class, bundle);
                                });
                                spStr.setSpan(firstSpan, 0, data.getCreateStaffName().length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
                                spStr.setSpan(secondSpan, spStr.toString().indexOf("@"), spStr.toString().indexOf("@") + 1 + data.getParentStaffName().length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
                                textView.setMovementMethod(LinkMovementMethod.getInstance());
                                textView.setText(spStr);
                            });
                        }
                    }).attachTo(recyclerView).updateData(commentResultBeen);
                    ItemClickSupport.addTo(recyclerView)
                            .setOnItemClickListener((recyclerView1, position, v) -> {
                                WorkDiaryBean.CommentBean dataItem = slimAdapterExCommentChild.getDataItem(position);
                                isMyComment = dataItem.getCreater().equals(AppConstent.user.getGuid());
                                commentId = dataItem.getId();
                                parentId = dataItem.getId();
                                parentUserGuid = dataItem.getCreater();
                                firstCommentId = data.getId();
                                talkTo = dataItem.getCreateStaffName();
                                talkContent = dataItem.getContent();
                                type = 2;
                                slimTalkAdapter = slimAdapterExCommentChild;
                                isCommentUp = false;
                                dealPos = position;
                                showMoreDialog(id);
                            });

                    injector.with(R.id.iv_comment_head, v -> ImageUtil.setCircleImage(data.getCreatePhoto(), (ImageView) v))
                            .text(R.id.tv_comment_up_left, data.getCreateStaffName())
                            .text(R.id.tv_comment_down_right, RongDateUtils.getConversationFormatDate(sf.parse(data.getCreateTime()).getTime(), WorkDiaryCommentActivity.this))
                            .text(R.id.tv_comment_down_left, data.getCreateDepartment() + " " + data.getCreatePost())
                            .text(R.id.tv_comment, data.getContent())
                            .visibility(R.id.tv_more_comment, data.getCommentCount() > 3 ? View.VISIBLE : View.GONE)
                            .text(R.id.tv_more_comment, String.format("展开更多%d条评论", data.getCommentCount()))
                            .clicked(R.id.tv_more_comment, v -> {

                                Bundle bundle = new Bundle();
                                WorkDiaryBean.CommentBean bean = data;
                                bean.setChildList(null);
                                bundle.putSerializable(Config.BEAN, bean);
                                bundle.putInt(Config.ID, id);
                                bundle.putString(Config.TYPE, mType);
                                startActivity(WorkDiaryChildCommentActivity.class, bundle);
                            })
                            .clicked(R.id.iv_comment_comment, v -> {
                                diaryId = id;
                                talkTo = data.getCreateStaffName();
                                parentId = data.getId();
                                parentUserGuid = data.getCreater();
                                firstCommentId = data.getId();
                                slimTalkAdapter = slimAdapterExCommentChild;
                                isCommentUp = true;
                                dealPos = mSlimAdapterEx.getData().indexOf(data);
                                talkTo();
                            })
                            .clicked(R.id.tv_comment, v -> {
                                isMyComment = data.getCreater().equals(AppConstent.user.getGuid());
                                parentId = data.getId();
                                parentUserGuid = data.getCreater();
                                firstCommentId = data.getId();
                                commentId = data.getId();
                                talkTo = data.getCreateStaffName();
                                talkContent = data.getContent();
                                type = 1;
                                slimTalkAdapter = slimAdapterExCommentChild;
                                isCommentUp = true;
                                dealPos = mSlimAdapterEx.getData().indexOf(data);
                                showMoreDialog(id);
                            })
                            .clicked(R.id.iv_comment_head, view -> {
                                Bundle bundle = new Bundle();
                                bundle.putString(Config.GUID, data.getCreater());
                                startActivity(UserCardActivity.class, bundle);
                            });

                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }).attachTo(dataBinding.recyclerView).updateData(new ArrayList());


        HashMap<String, String> map = new HashMap<>();
        String url;
        String detailUrl;
        if ("1".equals(mType)) { //任务
            url = HttpConfig.BASE_URL + HttpConfig.TASK_COMMENT;
            detailUrl = HttpConfig.BASE_URL + HttpConfig.RENWU_INFO;
            map.put("taskId", id + "");
        } else if ("0".equals(mType)) {//日志
            url = HttpConfig.BASE_URL + HttpConfig.DIARY_COMMIT;
            detailUrl = HttpConfig.BASE_URL + HttpConfig.DIARY_DETAIL;
            map.put("dailyId", id + "");
        } else {
            return;
        }
        ModelRx2DataSource<WorkDiaryBean.CommentBean> dataSource = new ModelRx2DataSource<>(new ModelRx2DataSource.OnLoadSource() {
            @Override
            public Flowable<List> loadSource(int page, Rx2DataSource.DoneActionRegister register) {
                pageNum = page == 1 ? 0 : pageNum;
                return OkGo.<HttpResult<List<WorkDiaryBean.CommentBean>>>post(url)
                        .params("page", pageNum)
                        .params(map)
                        .converter(new JsonConverter<HttpResult<List<WorkDiaryBean.CommentBean>>>() {
                            @Override
                            public void test() {
                                super.test();
                            }
                        }).adapt(new FlowableBody<>())
                        .flatMap(listResultBean -> {
                            pageNum = listResultBean.getPage();
                            if (listResultBean.getStatus() == 200) {
                                return Flowable.just(listResultBean.getItems() == null ? new ArrayList<WorkDiaryBean.CommentBean>() : listResultBean.getItems());
                            } else {
                                ToastUtil.showShort(listResultBean.getMsg());
                                return Flowable.just(new ArrayList<>());
                            }
                        });

            }
        });
        if ("0".equals(mType)) {//日志
            dataBinding.layoutDiary.setVisibility(View.VISIBLE);
            dataBinding.layoutHead.removeAllViews();
            ImageUtil.setCircleImage(getIntent().getStringExtra(Config.PHONE), dataBinding.ivDiaryHead);
            dataBinding.stvDiaryName.setText(getIntent().getStringExtra(Config.NAME));
            dataBinding.tvDiaryDepart.setText(getIntent().getStringExtra(Config.DEPARTMENT));
            dataBinding.tvDiaryTime.setText(getIntent().getStringExtra(Config.NOW_TIME));
            mSlimAdapterEx.addHeader(dataBinding.layoutDiary);
            OkGo.<HttpResult<WorkDiaryBean>>post(detailUrl)
                    .params(map)
                    .params("userGuid", user.getGuid())
                    .converter(new JsonConverter<HttpResult<WorkDiaryBean>>() {
                        @Override
                        public void test() {
                            super.test();
                        }
                    })
                    .adapt(new FlowableBody<HttpResult<WorkDiaryBean>>())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<HttpResult<WorkDiaryBean>>() {
                        @Override
                        public void accept(HttpResult<WorkDiaryBean> result) throws Exception {
                            WorkDiaryBean bean = result.getItems();
                            if (bean != null) {
                                if (bean.getLocation() != null && !"".equals(bean.getLocation())) {
                                    dataBinding.tvCity.setVisibility(View.VISIBLE);
                                    dataBinding.tvCity.setText(bean.getLocation());
                                } else {
                                    dataBinding.tvCity.setVisibility(View.GONE);
                                }
                                dataBinding.tvFilling.setText(bean.getFeeling());
                                if (bean.getPlan() != null && bean.getPlan().size() > 0) {
                                    dataBinding.layoutPlan.setVisibility(View.VISIBLE);
                                    for (int i = 0; i < bean.getPlan().size(); i++) {
                                        WorkDiaryBean.ItemBean itemBean = bean.getPlan().get(i);
                                        View view = inflater.inflate(R.layout.list_item_140, null);
                                        ((TextView) view.findViewById(R.id.tv_comment_comment)).setText(String.format(Locale.CHINA, "%s. %s", i + 1, itemBean.getContent()));
                                        dataBinding.layoutPlanItem.addView(view);
                                    }
                                } else {
                                    dataBinding.layoutPlan.setVisibility(View.GONE);
                                }
                                if (bean.getMatter() != null && bean.getMatter().size() > 0) {
                                    dataBinding.layoutMatter.setVisibility(View.VISIBLE);
                                    for (int i = 0; i < bean.getMatter().size(); i++) {
                                        WorkDiaryBean.ItemBean itemBean = bean.getMatter().get(i);
                                        View view = inflater.inflate(R.layout.list_item_140, null);
                                        ((TextView) view.findViewById(R.id.tv_comment_comment)).setText(String.format(Locale.CHINA, "%s. %s", i + 1, itemBean.getContent()));
                                        dataBinding.layoutMatterItem.addView(view);
                                    }
                                } else {
                                    dataBinding.layoutMatter.setVisibility(View.GONE);
                                }
                                if (bean.getTomorrowMatter() != null && bean.getTomorrowMatter().size() > 0) {
                                    dataBinding.layoutTomorrowMatter.setVisibility(View.VISIBLE);
                                    for (int i = 0; i < bean.getTomorrowMatter().size(); i++) {
                                        WorkDiaryBean.ItemBean itemBean = bean.getTomorrowMatter().get(i);
                                        View view = inflater.inflate(R.layout.list_item_140, null);
                                        ((TextView) view.findViewById(R.id.tv_comment_comment)).setText(String.format(Locale.CHINA, "%s. %s", i + 1, itemBean.getContent()));
                                        dataBinding.layoutTomorrowMatterItem.addView(view);
                                    }
                                } else {
                                    dataBinding.layoutTomorrowMatter.setVisibility(View.GONE);
                                }
                            }
                        }
                    });


        } else if ("1".equals(mType)) {//任务
            dataBinding.layoutTask.setVisibility(View.VISIBLE);
            dataBinding.layoutHead.removeAllViews();
            ImageUtil.setCircleImage(getIntent().getStringExtra(Config.PHONE), dataBinding.ivHead);
            dataBinding.stvName.setText(getIntent().getStringExtra(Config.NAME));
            dataBinding.tvDepart.setText(getIntent().getStringExtra(Config.DEPARTMENT));
            dataBinding.tvTime.setText(getIntent().getStringExtra(Config.NOW_TIME));
            mSlimAdapterEx.addHeader(dataBinding.layoutTask);
            OkGo.<HttpResult<RenwuInfoResultBean>>post(detailUrl)
                    .params(map)
                    .params("userGuid", user.getGuid())
                    .converter(new JsonConverter<HttpResult<RenwuInfoResultBean>>() {
                        @Override
                        public void test() {
                            super.test();
                        }
                    })
                    .adapt(new FlowableBody<HttpResult<RenwuInfoResultBean>>())
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Consumer<HttpResult<RenwuInfoResultBean>>() {
                        @Override
                        public void accept(HttpResult<RenwuInfoResultBean> result) throws Exception {
                            RenwuInfoResultBean bean = result.getItems();
                            dataBinding.tvTaskStatus.setText(String.format(Locale.CHINA, "%s【%s】", bean.getTaskName(), bean.getCompleteMessage()));
                            if (bean.getCompleteImageUrls() != null && bean.getCompleteImageUrls().size() > 0) {
                                dataBinding.recyclerViewImg.setVisibility(View.VISIBLE);
                                setRecyclerViewMoveFast(new LinearLayoutManager(WorkDiaryCommentActivity.this), dataBinding.recyclerViewImg);
                                dataBinding.recyclerViewImg.setLayoutManager(new GridLayoutManager(WorkDiaryCommentActivity.this, 3));
                                ImageView[] imageViews = new ImageView[bean.getCompleteImageUrls() == null ? 0 : bean.getCompleteImageUrls().size()];
                                SlimAdapterEx.create().register(R.layout.list_item_full_img, new SlimInjector<String>() {
                                    @Override
                                    public void onInject(String data, IViewInjector injector) {
                                        imageViews[bean.getCompleteImageUrls().indexOf(data)] = (ImageView) injector.findViewById(R.id.iv_img);
                                        injector.with(R.id.iv_img, v -> {
                                            ImageUtil.setImage(data, (ImageView) v);
                                        }).clicked(R.id.iv_img, v -> {
                                            dataBinding.vImageWatcher.setBackgroundColor(Color.parseColor("#000000"));
                                            dataBinding.vImageWatcher.show((ImageView) v, Arrays.asList(imageViews), bean.getCompleteImageUrls());
                                        });
                                    }
                                }).attachTo(dataBinding.recyclerViewImg).updateData(bean.getCompleteImageUrls());
                            }


                        }
                    });
        }


        mvcHelper = new MVCCoolHelper<>(dataBinding.coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(mSlimAdapterEx);
        mvcHelper.refresh();
    }


    @Override
    public void setView() {


    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {
            case R.id.tv_msg:
                diaryId = id;
                parentId = 0;
                firstCommentId = 0;
                parentUserGuid = "";
                talkTo = getIntent().getStringExtra(Config.NAME);
                slimTalkAdapter = null;
                talkTo();
                break;
        }
    }

    @Override
    public void onBackPressed() {

        if (dataBinding.vImageWatcher.isShown()) {
            dataBinding.vImageWatcher.onSingleTapConfirmed();
        } else {
            super.onBackPressed();
        }
    }


    private void showMoreDialog(int id) {
        if (moreDialog == null) {
            ArrayList<Object> objects = new ArrayList<>();
            objects.add("回复");
            objects.add("复制");
            objects.add("删除");
            SlimAdapterEx slimAdapterEx = SlimAdapterEx.create().registerDefault(R.layout.list_item_54, new SlimInjector() {
                @Override
                public void onInject(Object data, IViewInjector injector) {

                    injector.text(R.id.tv_content, (String) data);
                }
            }).updateData(objects);
            moreDialog = new MaterialDialog.Builder(this)
                    .adapter(slimAdapterEx, new LinearLayoutManager(this))
                    .build();
            moreDialog.getRecyclerView().addItemDecoration(new SectionDividerItemDecoration(this)
                    .setHeadHeight(0)
                    .setRightPadding(DensityUtil.percentW(40))
                    .setLeftPadding(DensityUtil.percentW(40))
                    .setLastBootomHeght(0));
            ItemClickSupport.addTo(moreDialog.getRecyclerView())
                    .setOnItemClickListener((recyclerView, position, v) -> {
                        switch (position) {
                            case 0:
                                this.diaryId = id;
                                talkTo();
                                break;
                            case 1:
                                CopyUtil.copy(talkContent);
                                break;
                            case 2:
                                deleteWorkDiaryComment(commentId, type, () -> {
                                    if (isCommentUp) {
                                        mSlimAdapterEx.getData().remove(dealPos);
                                        mSlimAdapterEx.notifyItemRemoved(dealPos);
                                    } else {
                                        slimTalkAdapter.getData().remove(dealPos);
                                        slimTalkAdapter.notifyItemRemoved(dealPos);
                                    }
                                    mvcHelper.refresh();
                                });
                                break;
                        }
                        moreDialog.dismiss();
                    });
        }
        SlimAdapterEx slimAdapterExMore = (SlimAdapterEx) moreDialog.getRecyclerView().getAdapter();
        if (isMyComment && slimAdapterExMore.getData().size() == 2) {
            slimAdapterExMore.getData().add("删除");
            slimAdapterExMore.notifyItemInserted(2);
        } else if (!isMyComment && slimAdapterExMore.getData().size() == 3) {
            slimAdapterExMore.getData().remove(2);
            slimAdapterExMore.notifyItemRemoved(2);
        }
        moreDialog.show();

    }


    private void setRecyclerViewMoveFast(RecyclerView.LayoutManager layoutManager, RecyclerView recyclerView) {
        recyclerView.setLayoutManager(layoutManager);
        layoutManager.setAutoMeasureEnabled(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
    }

    private void talkTo() {
        Bundle bundle = new Bundle();
        bundle.putString(Config.TALK_TO, talkTo);
        startActivityForResult(InputDialogActivity.class, bundle, Config.INPUT);
    }

    private void buttonBackGround(TextView textView, IViewInjector injector) {
        injector.background(R.id.tv_filling, R.drawable.bg_shape_click_gray);
        injector.background(R.id.tv_plan, R.drawable.bg_shape_click_gray);
        injector.background(R.id.tv_matter, R.drawable.bg_shape_click_gray);
        injector.background(R.id.tv_tomorrow_matter, R.drawable.bg_shape_click_gray);
        textView.setBackgroundResource(R.color.gray9);
    }


    public void commentWorkDiary(int articleId, int parentId, String content, String parentUserGuid, int firstCommentId, HttpUtil.ResultObjectBack resultBack) {
        String url;
        HashMap<String, String> map = new HashMap<>();
        if ("0".equals(mType)) {
            url = HttpConfig.BASE_URL + HttpConfig.DIARY_ADD_COMMIT;
            map.put("dailyId", articleId + "");
        } else if ("1".equals(mType)) {
            url = HttpConfig.BASE_URL + HttpConfig.TASK_ADD_COMMENT;
            map.put("taskId", articleId + "");
        } else {
            return;
        }

        OkGo.<HttpResult<WorkDiaryBean.CommentBean>>post(url)
                .params("userGuid", AppConstent.user.getGuid())
                .params(map)
                .params("parentId", parentId)
                .params("message", content)
                .params("parentUserGuid", parentUserGuid)
                .params("firstCommentId", firstCommentId)
                .execute(new DialogCallBack<HttpResult<WorkDiaryBean.CommentBean>>(WorkDiaryCommentActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult<WorkDiaryBean.CommentBean>> response) {
                        HttpResult<WorkDiaryBean.CommentBean> httpResult = response.body();
                        // ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            resultBack.onResultBack(httpResult.getItems());
                        }
                    }
                });
    }

    public void deleteWorkDiaryComment(int commentId, int type, HttpUtil.ResultBack resultBack) {
        String url;
        if ("0".equals(mType)) {
            url = HttpConfig.BASE_URL + HttpConfig.DIARY_DELETE_COMMENT;
        } else if ("1".equals(mType)) {
            url = HttpConfig.BASE_URL + HttpConfig.TASK_DELETE_COMMENT;
        } else {
            return;
        }
        OkGo.<HttpResult>post(url)
                .params("userGuid", AppConstent.user.getGuid())
                .params("commentId", commentId)
                .params("type", type)
                .execute(new DialogCallBack<HttpResult>(WorkDiaryCommentActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult> response) {
                        HttpResult httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            resultBack.onResultBack();
                        }
                    }
                });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == Config.INPUT && resultCode == Config.SUCCESS) {
            String content = data.getStringExtra(Config.CONTENT);
            commentWorkDiary(diaryId, parentId, content, parentUserGuid, firstCommentId, (commentBean) -> {
                if (slimTalkAdapter == null) {
                    mSlimAdapterEx.getData().add(0, (WorkDiaryBean.CommentBean) commentBean);
                    mSlimAdapterEx.notifyItemInserted(0);
                } else if (isCommentUp) {
                    slimTalkAdapter.getData().add(0, (WorkDiaryBean.CommentBean) commentBean);
                    slimTalkAdapter.notifyItemInserted(0);
                } else {
                    slimTalkAdapter.getData().add((WorkDiaryBean.CommentBean) commentBean);
                    slimTalkAdapter.notifyItemInserted(slimTalkAdapter.getData().size() - 1);
                }
                mvcHelper.refresh();
            });
        }
    }
}
